'abupositioncomponent.monkey by Belimoth

'TODO

Strict
Import abucomponent



Interface IPosition
	Method X:Int() Property
	Method X:Void(xNew:Int) Property
	Method Y:Int() Property
	Method Y:Void(yNew:Int) Property
	Method Position:Position() Property
	Method SetPosition:Void(x:Int, y:Int)
	
	Method DistanceTo:Float(other:IPosition)
	Method AngleTo:Float(other:IPosition)
End



Class Position Implements IPosition

Public
	Method X:Int() Property Return _x End
	Method X:Void(xNew:Int) Property _x = xNew End
	Method Y:Int() Property Return _y End
	Method Y:Void(yNew:Int) Property _y = yNew End
	Method Position:Position() Property Return Copy() End
	
	Method New(x:Int, y:Int)
		Self._x = x
		Self._y = y
	End
	
	Method SetPosition:Void(xNew:Int, yNew:Int)
		_x = xNew
		_y = yNew
	End
	
	Method DistanceTo:Float(other:IPosition)
		Local dx:Float = _x - other.X
		Local dy:Float = _y - other.Y
		Return Sqrt(dx*dx + dy*dy)
	End
	
	Method AngleTo:Float(other:IPosition)
		Local dx:Float = _x - other.X
		Local dy:Float = _y - other.Y
		Return ( 450 - ATan2(dx, dy) ) Mod 360
	End
	
	'Method VectorTo:Vector(other:IPosition)
		'TODO
	'End

Private
	Field _x:Int, _y:Int
	
	Method Copy:Position()
		Return New Position(_x, _y)
	End
End



Class PositionComponent Extends EntityComponent Implements IPosition

Public
	Method X:Int() Property																		Return _position.X;														End
	Method X:Void(xNew:Int) Property															_position.X = xNew;														End
	Method Y:Int() Property																		Return _position.Y;														End
	Method Y:Void(yNew:Int) Property															_position.Y = yNew;														End
	Method Position:Position() Property															Return _position.Position;												End
	Method SetPosition:Void(xNew:Int, yNew:Int)													_position.SetPosition(xNew, yNew);										End
	Method DistanceTo:Float(other:IPosition)													Return _position.DistanceTo(other);										End
	Method AngleTo:Float(other:IPosition)														Return _position.AngleTo(other);										End
	'Method VectorTo:Vector(other:IPosition)													Return _position.VectorTo(other);										End
	
Private
	Field _position := New Position()
End